import com.atshiyou.bean.Student;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.Reader;
import java.util.HashMap;
import java.util.Map;

public class Test3 {
    public static void main(String[] args) throws Exception {
//        1、加载配置文件
        Reader reader = Resources.getResourceAsReader("mybatis.xml");
        //2、得到SqlSessionFactoryBuilder
        SqlSessionFactoryBuilder builder = new SqlSessionFactoryBuilder();
        SqlSessionFactory build = builder.build(reader,"development2");
        //3、得到session对象
        SqlSession session = build.openSession();
        // 4、操作SQL
        Map map= new HashMap<>();
        map.put("stuname","嘻嘻");
        map.put("stuage",21);
        int insert = session.insert("com.atshiyou.dao.StudentDao.insert2", map);
        session.commit();//还要提交事务，否则数据库里不会新增值
        System.out.println(insert);
        session.close();
        reader.close();

    }
}
